<?php
if(!isset($AppUI->id) || $AppUI->id <=0 || ($AppUI->id > 0 && $AppUI->type != ROLE_ROOT)) {
	redirect(HOST_BACKEND);
}
// data input
$strCode		= $this->input->post('pcode', '');
$strName		= $this->input->post('pname', '');
$intPermA		= $this->input->post('pperm_a', 0);
$arrErr		    = null;
// strip tag data input
$strCode        = CI_Function::stripTag($strCode, 'code');
$strName        = CI_Function::stripTag($strName, 'name');
if($strCode == '') $arrErr[]	= $arrLocale['code_required'];
if($strCode != '' && !CI_Function::isValidCode($strCode)) $arrErr[] = $arrLocale['code_format'];
if($strName == '') $arrErr[] = $arrLocale['name_required'];
if(!isset($arrErr)) {
	if(isset($_SESSION['SECTION_PARAM'])) unset($_SESSION['SECTION_PARAM']);
	if(isset($_SESSION['SECTION_ERROR'])) unset($_SESSION['SECTION_ERROR']);
	$this->load->model('section_model', 'section');
	$intError		= $this->section->add($strCode, $strName, $intPermA);
	if($intError > 0) $arrErr[] = $arrLocale['code_exists'];
	else redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : (HOST_BACKEND . 'section'));
}
if(isset($arrErr)) {
	$_SESSION['SECTION_ERROR']	= $arrErr;
	$_SESSION['SECTION_PARAM']	= $this->input->post();
}
redirect(HOST_BACKEND.'section/add');
